1 ================================================================================
2 WINDOWS FORMS APPLICATION : CSWinFormPassValueBetweenForms Project Overview
4 Pass Value Between Forms Sample
6 ===============================================================================
8 /////////////////////////////////////////////////////////////////////////////
11 The Pass Value Between Forms sample demonstrates how to pass value between forms.
13 There're two common ways to pass value between forms:
17 Create a public property on the target form class, then we can pass value
18 to the target form by setting value for the property.
22 Create a public method on the target form class, then we can pass value to
23 the target form by passing the value as parameter to the method.
26 /////////////////////////////////////////////////////////////////////////////
29 1. Create two forms named FrmPassValueBetweenForms and
30 FrmPassValueBetweenForms2 respectively;
32 2. Create a public property named ValueToPassBetweenForms in the
33 FrmPassValueBetweenForms2 class;
35 private string _valueToPassBetweenForms;
37 public string ValueToPassBetweenForms
39 get { return this._valueToPassBetweenForms; }
40 set { this._valueToPassBetweenForms = value; }
44 3. Create a public method named SetValueFromAnotherForm in the
45 FrmPassValueBetweenForms2 class;
47 public void SetValueFromAnotherForm(string val)
49 this._valueToPassBetweenForms = val;
52 4. On the FrmPassValueBetweenForms form, handle the Click event of the buttons.
53 In the Click event handler of button1, set the SetValueFromAnotherForm
54 property for the FrmPassValueBetweenForms2 to pass the text value from
55 FrmPassValueBetweenForms to FrmPassValueBetweenForms2.
56 In the Click event handler of button2, call the SetValueFromAnotherForm
57 method and pass the text value as parameter to the FrmPassValueBetweenForms2.
60 /////////////////////////////////////////////////////////////////////////////
63 1. Windows Forms General FAQ.
64 http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/77a66f05-804e-4d58-8214-0c32d8f43191
67 /////////////////////////////////////////////////////////////////////////////